package com.aldobucchi.x.flash.events.subscriber
{
	
	import flash.events.IEventDispatcher;
	
	import com.aldobucchi.x.flash.events.EventListenerSpec;

	
	internal class EventSubscriptionFinalStep extends AbstractEventSubscriptionStep
	{
		

		private var spec:EventListenerSpec;

		
		public function EventSubscriptionFinalStep( target:Object, spec:EventListenerSpec )
		{


			super( target, [] );

			this.spec = spec;

			
			if ( target is IEventDispatcher )
			{
				spec.addToDispatcher( target as IEventDispatcher );			
			}

		}
		


		/**
		 * 
		 * No child steps to kill. We just unsubscribe
		 * 
		 */
		override internal function kill( ):void
		{
			if ( target is IEventDispatcher )
			{
				spec.removeFromDispatcher( target as IEventDispatcher );			
			}
		}


		
	}

}